if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[QA_UpdateProtocolTitleVersion]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[QA_UpdateProtocolTitleVersion]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



/***************************************************************************
* Name:			QA_UpdateProtocolTitleVersion
* Purpose:		Using table Stg_ProtocolInsert, update certain columns on Protocol table.
*
***************************************************************************/
CREATE PROCEDURE dbo.QA_UpdateProtocolTitleVersion
(			
			@sFolderNumber varchar(12),
			@sProtocolTitle text,
			@sVersionName varchar(100)
)
AS
BEGIN
	SET NOCOUNT ON

	-- Title
	BEGIN
		UPDATE Protocol SET Title = @sProtocolTitle 
			WHERE Protocol.ProtocolNumber = @sFolderNumber
				and IsCurrent = 1
	END

	-- Version
	BEGIN
		UPDATE Protocol SET Version = @sVersionName 
			WHERE Protocol.ProtocolNumber = @sFolderNumber
			AND ISNULL(Protocol.Version, '') != ISNULL(@sVersionName, '')
			and IsCurrent = 1
	END

	SET NOCOUNT OFF

END


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO